package com.clock.web.controller.shop;

import com.clock.common.annotation.Log;
import com.clock.common.core.controller.BaseController;
import com.clock.common.core.domain.AjaxResult;
import com.clock.common.core.page.TableDataInfo;
import com.clock.common.enums.BusinessType;
import com.clock.common.utils.poi.ExcelUtil;
import com.clock.shop.domain.ShopShop;
import com.clock.shop.domain.vo.ShopShopVo;
import com.clock.shop.service.IShopShopService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 店铺Controller
 * 
 * @author ruoyi
 * @date 2024-10-11
 */
@RestController
@RequestMapping("/shop/shop")
public class ShopShopController extends BaseController
{
    @Autowired
    private IShopShopService shopShopService;

    /**
     * 查询店铺列表
     */
    // @PreAuthorize("@ss.hasPermi('shop:shop:list')")
    @GetMapping("/list")
    public TableDataInfo list(ShopShopVo shopShopVo)
    {
        startPage();
        List<ShopShopVo> list = shopShopService.selectShopShopList(shopShopVo);
        return getDataTable(list);
    }

    /**
     * 导出店铺列表
     */
    @PreAuthorize("@ss.hasPermi('shop:shop:export')")
    @Log(title = "店铺", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ShopShopVo shopShopVo)
    {
        List<ShopShopVo> list = shopShopService.selectShopShopList(shopShopVo);
        ExcelUtil<ShopShopVo> util = new ExcelUtil<ShopShopVo>(ShopShopVo.class);
        util.exportExcel(response, list, "店铺数据");
    }

    /**
     * 获取店铺详细信息
     */
    @PreAuthorize("@ss.hasPermi('shop:shop:query')")
    @GetMapping(value = "/{shopId}")
    public AjaxResult getInfo(@PathVariable("shopId") Long shopId)
    {
        return success(shopShopService.selectShopShopByShopId(shopId));
    }

    /**
     * 新增店铺
     */
    @PreAuthorize("@ss.hasPermi('shop:shop:add')")
    @Log(title = "店铺", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ShopShop shopShop)
    {
        return toAjax(shopShopService.insertShopShop(shopShop));
    }

    /**
     * 修改店铺
     */
    @PreAuthorize("@ss.hasPermi('shop:shop:edit')")
    @Log(title = "店铺", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ShopShop shopShop)
    {
        return toAjax(shopShopService.updateShopShop(shopShop));
    }

    /**
     * 删除店铺
     */
    @PreAuthorize("@ss.hasPermi('shop:shop:remove')")
    @Log(title = "店铺", businessType = BusinessType.DELETE)
	@DeleteMapping("/{shopIds}")
    public AjaxResult remove(@PathVariable Long[] shopIds)
    {
        return toAjax(shopShopService.deleteShopShopByShopIds(shopIds));
    }
}
